package two_xia.ex9.Demo07;

public class ObserverPattern {
    public static void main(String[] args) {
        // 创建战队成员
        AllyMember player1 = new AllyMember("玩家1");
        AllyMember player2 = new AllyMember("玩家2");
        AllyMember player3 = new AllyMember("玩家3");

        // 创建盟友
        Ally ally1 = new Ally("盟友1");
        Ally ally2 = new Ally("盟友2");

        // 盟友加入战队
        player1.attach(ally1);
        player1.attach(ally2);
        player2.attach(ally1);
        player3.attach(ally2);

        // 玩家1受到攻击，通知盟友
        player1.beAttacked("玩家1被敌人攻击了！");
    }
}